﻿using System;
using System.Text;
using System.Web.UI;
using phudieuhungthinh.BL;

namespace phudieuhungthinh.Pages
{
    public partial class ArticleCate : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override void CreateChildControls()
        {
            var im = new ArticleImpl();
            var featureIm = new FeatureArticleImpl();

            var html = new StringBuilder();
            html.Append("<div id='article-layout'>");
            var featureList = featureIm.GetFeatureArticles(ArticleType.Article, true);
            if (featureList != null && featureList.Count > 0)
            {
                html.Append(@"<div id='article-slide' class='cycle-slideshow' 
                data-cycle-fx=scrollHorz
                data-cycle-timeout=5000
                data-cycle-caption-plugin=caption2
                data-cycle-overlay-fx-out='fadeOut'
                data-cycle-overlay-fx-in='fadeIn'
                >
                <div class='cycle-overlay'></div>");
                foreach (var articleModel in featureList)
                {
                    html.AppendFormat(@"<img src='{0}' 
                        data-cycle-title='{1}' data-cycle-desc='{2}' />",
                        articleModel.Thumb, articleModel.Title, articleModel.ArticleSapo);
                }
                html.Append("</div>");
            }
            
            html.Append("<div id='article-list'>");
            var list = im.GetArticlesExceptFeature(ArticleType.Article, true);
            if (list != null && list.Count > 0)
            {
                html.Append("<div id='article-items'>");
                foreach (var articleModel in list)
                {
                    html.Append("<div class='item'>")
                        .AppendFormat("<a class='thumb' href='/tintuc/{0}'><img src='/hinh-anh/tin-tuc/{0}' alt='{1}' /></a>", articleModel.Url, articleModel)
                        .AppendFormat(@"<span class='content'>
                            <a class='title' href='/tintuc/{0}'>{1}</a>
                            <span class='sapo'>{2}</span>
                        </span>", articleModel.Url, articleModel.Title, articleModel.ArticleSapo)
                        .Append("</div>");
                }
                html.Append("</div>");
            }
            html.Append("</div>");
            containerUI.Controls.Add(new LiteralControl(html.ToString()));

            base.CreateChildControls();
        }
    }
}